package cn.maihe.elg.operation.centers.guogu.channel.service;

import cn.maihe.elg.operation.centers.guogu.channel.GuoGuBaseChannelService;
import cn.maihe.elg.operation.centers.guogu.dto.GuoGuBaseRespDTO;
import cn.maihe.elg.operation.centers.guogu.dto.channel.req.GuoGuReductionNotifyReq;
import cn.maihe.elg.operation.centers.guogu.enums.GuoGuChannelMethod;
import cn.maihe.elg.operation.centers.guogu.enums.GuoGuRespCodeEnum;
import cn.maihe.elg.operation.model.dto.InnerBaseResp;
import cn.maihe.elg.operation.model.enums.CenterNoEnum;
import cn.maihe.elg.operation.service.order.AcceptOrderInfoService;
import cn.maihe.elg.operation.supports.system.ElgResourceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Description 还原结果推送
 * @Author SSX
 * @Date 2025/03/18
 */
@Service
@Slf4j
public class GuoGuReductionNotifyChannelService extends GuoGuBaseChannelService<GuoGuReductionNotifyReq, GuoGuBaseRespDTO> {

    @Resource
    private ElgResourceService elgResourceService;
    @Resource
    private AcceptOrderInfoService acceptOrderInfoService;
    @Override
    protected GuoGuChannelMethod methodEnum() {
        return GuoGuChannelMethod.reduction_notify;
    }

    /**
     * 还原结果推送
     */
    public InnerBaseResp<GuoGuBaseRespDTO> reductionResultNotify(String clientId, GuoGuReductionNotifyReq guoGuInvoiceNotifyReq,CenterNoEnum centerNoEnum) {
        InnerBaseResp<GuoGuBaseRespDTO> innerBaseResp;
        try {
            GuoGuBaseRespDTO resp = this.doRequest(clientId, centerNoEnum, guoGuInvoiceNotifyReq);
            if (GuoGuRespCodeEnum.isSuccess(resp.getCode())) {
                innerBaseResp = InnerBaseResp.success(guoGuInvoiceNotifyReq.getInsureOrderNo());
            } else {
                innerBaseResp = InnerBaseResp.error(resp.getMsg());
            }
        } catch (Exception e) {
            log.error("还原结果推送>> [{}] 异常:{}", centerNoEnum.getCenterName(), e.getMessage(), e);
            innerBaseResp = InnerBaseResp.error("通知异常:" + e.getMessage());
        }

        return innerBaseResp;
    }
}
